using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Close.io.API
{
	public class CloseIoRequest
	{
		public string Query { get; set; }
		public int? Limit { get; set; }
		public int? Skip { get; set; }
		public IEnumerable<string> Fields { get; set; }

		public CloseIoRequest(string query, int? limit, int? skip, IEnumerable<string> fields)
		{
		
			Query = query;
			Limit = limit;
			Skip = skip;
			Fields = fields;
		}

		public CloseIoRequest()
		{
			
			Fields = new List<string>();
		}

		

		public override string ToString()
		{
			var buffer = new StringBuilder();

			buffer.AppendFormat("?query={0}", Query);
		
			if (Fields!=null && Fields.Any())
			{
				buffer.AppendFormat("&_fields={0}", string.Join(", ", Fields));
			}
			if (Skip != null)
			{
				buffer.AppendFormat("&_skip={0}", Skip);
			}

			if (Limit != null)
			{
				buffer.AppendFormat("&_limit={0}", Limit);
			}

			return buffer.ToString();
		}
	}
}